草庐IT

c++ getline和stringstream

全部标签

c - Valgrind 使用 getline() 给出错误

我有一个调用getline()的函数,它从标准文本文件中读取行。这些行以\r\n结尾,因为这是规范所要求的,因为它是VCARD文件的“互联网标准”。无论如何,我在OpenSUSE11.3上使用最新的GCC和Valgrind版本通过Valgrind运行这个宝贝;没有错误。但是,由于与此问题无关的原因,我将发行版切换到BackTrack4(基于Ubuntu),现在我收到了一大堆Valgrind错误:==21536==Conditionaljumpormovedependsonuninitialisedvalue(s)==21536==at0x40164A1:(within/lib/ld-2

c - Valgrind 使用 getline() 给出错误

我有一个调用getline()的函数,它从标准文本文件中读取行。这些行以\r\n结尾,因为这是规范所要求的,因为它是VCARD文件的“互联网标准”。无论如何,我在OpenSUSE11.3上使用最新的GCC和Valgrind版本通过Valgrind运行这个宝贝;没有错误。但是,由于与此问题无关的原因,我将发行版切换到BackTrack4(基于Ubuntu),现在我收到了一大堆Valgrind错误:==21536==Conditionaljumpormovedependsonuninitialisedvalue(s)==21536==at0x40164A1:(within/lib/ld-2

android - TelephonyManager.getLine1Number() 失败?

我想获取安卓设备的电话号码。我使用此代码:TelephonyManagertm=(TelephonyManager)this.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);StringphoneNumber=tm.getLine1Number();在我的手机(HTCWildfire)上,我无法获取电话号码-我得到的只是空字符串。如果我在模拟器上运行代码,通常会显示电话号码。如果我转到设置=>关于电话=>电话身份->电话号码,电话号码是“未知”。问题出在哪里?我的SIM卡有问题吗?

android - TelephonyManager.getLine1Number() 失败?

我想获取安卓设备的电话号码。我使用此代码:TelephonyManagertm=(TelephonyManager)this.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);StringphoneNumber=tm.getLine1Number();在我的手机(HTCWildfire)上,我无法获取电话号码-我得到的只是空字符串。如果我在模拟器上运行代码,通常会显示电话号码。如果我转到设置=>关于电话=>电话身份->电话号码,电话号码是“未知”。问题出在哪里?我的SIM卡有问题吗?

c++ - 使用 stringstream 而不是 `sscanf` 来解析固定格式的字符串

我想使用stringstream提供的工具从固定格式string中提取值作为sscanf的类型安全替代方案>。我该怎么做?考虑以下特定用例。我有以下固定格式的std::string:YYYYMMDDHHMMSSmmm地点:YYYY=4digitsrepresentingtheyearMM=2digitsrepresentingthemonth('0'paddedto2characters)DD=2digitsrepresentingtheday('0'paddedto2characters)HH=2digitsrepresentingthehour('0'paddedto2charac

c++ - 使用 stringstream 而不是 `sscanf` 来解析固定格式的字符串

我想使用stringstream提供的工具从固定格式string中提取值作为sscanf的类型安全替代方案>。我该怎么做?考虑以下特定用例。我有以下固定格式的std::string:YYYYMMDDHHMMSSmmm地点:YYYY=4digitsrepresentingtheyearMM=2digitsrepresentingthemonth('0'paddedto2characters)DD=2digitsrepresentingtheday('0'paddedto2characters)HH=2digitsrepresentingthehour('0'paddedto2charac

c++ - std 没有成员 'getline' ?

我正在尝试使用std::getline,但我的编译器告诉我getline未识别?#include#include#include#include#include#includeintmain(){usingnamespacestd;stringline;ifstreamifile("test.in");if(ifile.is_open()){while(ifile.good()){getline(ifile,line);}}} 最佳答案 std::getline在string中定义标题。#include另外,您的代码没有使用cstr

c++ - std 没有成员 'getline' ?

我正在尝试使用std::getline,但我的编译器告诉我getline未识别?#include#include#include#include#include#includeintmain(){usingnamespacestd;stringline;ifstreamifile("test.in");if(ifile.is_open()){while(ifile.good()){getline(ifile,line);}}} 最佳答案 std::getline在string中定义标题。#include另外,您的代码没有使用cstr

c++ - std::stringstream 和 str 方法

我在尝试使用stringstream对象时注意到了一些事情。这是一个无用的例子来解释这一点:stringstreamss;ss不等于cout这会导致编译错误,提示“classstd::basic_ostream”没有名为“str”的成员。我无法轻易解释这一点。这对我的应用程序来说并不重要,但我很确定这隐藏了一个有趣的C++技巧。注意:我在c++14中使用gcc 最佳答案 operator没有为std::stringstream定义,但对于它的基类std::ostream,因此它不返回对std::stringstream的引用因此方法

c++ - std::stringstream 和 str 方法

我在尝试使用stringstream对象时注意到了一些事情。这是一个无用的例子来解释这一点:stringstreamss;ss不等于cout这会导致编译错误,提示“classstd::basic_ostream”没有名为“str”的成员。我无法轻易解释这一点。这对我的应用程序来说并不重要,但我很确定这隐藏了一个有趣的C++技巧。注意:我在c++14中使用gcc 最佳答案 operator没有为std::stringstream定义,但对于它的基类std::ostream,因此它不返回对std::stringstream的引用因此方法